package com.myrpc.transfer.dto;

import com.myrpc.emnus.RpcResponseCode;
import lombok.*;

import java.io.Serializable;

/**
 * Rpc调用返回值 网络传播实体类
 */
@ToString
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Builder
public class RpcResponse<T> implements Serializable {

    private static final long serialVersionUID = 6622812491440393775L;
    private String requestId;
    private Integer code;
    private String message;
    private T data;

    /**
     * 调用成功
     */
    public static <T> RpcResponse<T> success(T data, String requestId){
        RpcResponse<T> response = new RpcResponse<T>();
        response.setCode(RpcResponseCode.SUCCESS.getCode());
        response.setMessage(RpcResponseCode.SUCCESS.getMessage());
        response.setRequestId(requestId);
        response.setData(data);
        return response;
    }
    public static <T> RpcResponse<T> fail(){
        RpcResponse<T> response = new RpcResponse<T>();
        response.setCode(RpcResponseCode.FAIL.getCode());
        response.setMessage(RpcResponseCode.FAIL.getMessage());
        return response;
    }
}
